<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1 {
            text-align: center;
        }

        .box2 {
            text-align: center;
        }

        /* .box2 span {
            display: block;
            text-align: center;
        } */
    </style>
</head>

<body>
    <p class="box1">段落</p>
    <!-- 能让行内元素水平居中 -->
    <p class="box2">
        <span>段落2</span>
    </p>
    <!--text-align: center能让行内块元素水平居中  -->
    <div style="text-align: center;">
        <img src="./images/1.jpg" alt="">
    </div>
    <!-- 块元素需要水平居中需要设置宽度margin: auto; -->
    <div style="background: red;width: 80%;margin: auto;">
        1
    </div>

</body>

</html>